package com.ktjy.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseController {

    public String forward(String url){
        return UrlBasedViewResolver.FORWARD_URL_PREFIX+url;
    }

    public String redirect(String url){
        return UrlBasedViewResolver.REDIRECT_URL_PREFIX+url;
    }

    @InitBinder
    public void initBinder(WebDataBinder dataBinder){
        dataBinder.registerCustomEditor(Date.class,
                new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
    }

}
